/**
 * Copyright (c) [2022] LiuGang(libbylg@126.com)
 * TinyEditor is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *             http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef VM_IMPL_H
#define VM_IMPL_H

#ifndef NDEBUG
#include <cassert>
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif

#include "vm.h"

#define VM_STACK_SIZE_MAX (32 * 1024)
#define VM_ERROR_BUFFER_SIZE (256)
#define VM_FRAME_DEPTH_MAX (20)

struct vm_frame_t {
    uint64_t pc;
    uint64_t regs[VM_REG_CALL_NUM];
};

struct vm_t {
    const vm_inst_t* insts;
    size_t insts_num;
    uint64_t regs[VM_REG_COUNT];
    uint64_t stacks[VM_STACK_SIZE_MAX / sizeof(uint64_t)];
    char error[VM_ERROR_BUFFER_SIZE]; // 首字节为长度
    vm_frame_t frames[VM_FRAME_DEPTH_MAX];
};

#endif // VM_IMPL_H
